package com.lanou3g.farmdoctor.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou3g.farmdoctor.R;
import com.lanou3g.farmdoctor.entity.AnswerBean;
import com.lanou3g.farmdoctor.volley.VolleySingleton;
import com.lanou3g.farmdoctor.widget.RoundImageView;

import java.util.List;

/**
 * Created by ChenFengYao on 15/11/26.
 * 问答详情页面的适配器
 */
public class AnswerListAdapter extends BaseAdapter {
    private VolleySingleton volleySingleton;
    private Context context;
    private List<AnswerBean.RepliesEntity> repliesEntities;
    public AnswerListAdapter(Context context) {
        this.context = context;
    }

    //添加数据
    public void addData(List<AnswerBean.RepliesEntity> repliesEntities){
        this.repliesEntities = repliesEntities;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return repliesEntities==null?0:repliesEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.list_item_answer,
                    parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        AnswerBean.RepliesEntity repliesEntity = repliesEntities.get(position);

        viewHolder.answerName.setText(repliesEntity.getReplier().getName());
        viewHolder.answerRank.setText(repliesEntity.getReplier().getEtInfo().getV());
        viewHolder.answerContent.setText(repliesEntity.getContent());
        viewHolder.answerPlace.setText(repliesEntity.getReplier().getArea());

        return convertView;
    }

    class ViewHolder{
        TextView answerName,answerRank,answerTime,answerContent,answerPlace;
        RoundImageView headIcon;
        public ViewHolder(View view) {
            answerName = (TextView) view.findViewById(R.id.tv_answer_name);
            answerRank = (TextView) view.findViewById(R.id.tv_answer_rank);
            answerTime = (TextView) view.findViewById(R.id.tv_answer_time);
            answerContent = (TextView) view.findViewById(R.id.tv_answer_content);
            answerPlace = (TextView) view.findViewById(R.id.tv_answer_place);
            headIcon = (RoundImageView) view.findViewById(R.id.riv_answer_head_icon);
        }
    }
}
